home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / aaem95ma.zip / FINDMODE.CC < prev    next >
C/C++ Source or Header  |  1994-09-19  |  3KB  |  70 lines

  1. #include <std.h>
  2. #include <pc.h>
  3. #include <stdio.h>
  4. #define byte unsigned char
  5. #define uns unsigned
  6. #define split(a,b,ab) ((a)=(ab)>>16,(b)=(ab)&0xffff)
  7. long _ax=0,_bx=0,_cx=0,_dx=0,_si=0,_di=0,_sp=0; short _flags; void* _bp=0;
  8. #define _al (*((byte*)&_ax))
  9. #define _bl (*((byte*)&_bx))
  10. #define _cl (*((byte*)&_cx))
  11. #define _dl (*((byte*)&_dx))
  12. #define _ah (*(((byte*)&_ax)+1))
  13. #define _bh (*(((byte*)&_bx)+1))
  14. #define _ch (*(((byte*)&_cx)+1))
  15. #define _dh (*(((byte*)&_dx)+1))
  16. #define _carry (_flags&1)
  17. #define _zeroflag (_flags&0x40)
  18. #define declint(n) \
  19.   void int##n(){asm("pushf"); asm("movl %ebp,__bp"); asm("movl %esp,__sp"); \
  20.   asm("xchgl __ax,%eax"); asm("xchgl __bx,%ebx"); asm("xchgl __cx,%ecx"); \
  21.   asm("xchgl __dx,%edx"); asm("xchgl __si,%esi"); asm("xchgl __di,%edi"); \
  22.   asm("int $0x"#n); asm("pushf"); asm("popw __flags"); \
  23.   asm("xchgl __ax,%eax"); asm("xchgl __bx,%ebx"); asm("xchgl __cx,%ecx"); \
  24.   asm("xchgl __dx,%edx"); asm("xchgl __si,%esi"); asm("xchgl __di,%edi"); \
  25.   asm("xchgl __bp,%ebp"); asm("xchgl __sp,%esp"); asm("popf");}
  26. /*-----*/
  27. declint(10); declint(11); declint(12); declint(13); declint(14); declint(15);
  28. declint(16); declint(17); declint(18); declint(19); declint(1a); declint(21);
  29. declint(25); declint(26); declint(27); declint(2f); declint(33); declint(67);
  30. /*----- = current screen mode */
  31. int gp_mode(void) {_ax=0xf00; int10(); return _ax&255;}
  32. /*----- screen mode := m */
  33. int gp_mode(char m) {_ax=m&255; int10(); return gp_mode();}
  34. /*-----*/
  35. int __; /* dustbin if int* arg not wanted */
  36. int setscreenmode(byte md,int*ncols=&__,int erasescr=1){
  37.   _ah=0; _al=md|(erasescr?0:128); int10();
  38.   _ah=0xf; int10(); *ncols=_ah; return _al-(md&127);} /* 0 = OK */
  39. byte getscreenmode(int*ncols=&__,int*pag=&__){
  40.   _ah=0xf; int10(); *ncols=_ah; *pag=_bh; return _al;}
  41. /*-----*/
  42. main(int nargs,char**arg){int i,n,m=getscreenmode(),M[256]; char s[128];
  43. printf("screen mode = %2X hex = %3d decimal\n",m,m); if(nargs<2) exit(0);
  44. strcpy(s,arg[1]); n=strlen(s);
  45. for(i=0;i<n;i++) if(s[i]>='A') if(s[i]<='Z') s[i]+='a'-'A';
  46. if(!strcmp(s,"all")) {
  47.     for(i=0;i<128;i=i==8?0xd:i+1) {setscreenmode(i); M[i]=getscreenmode()==i;}
  48.     setscreenmode(m); printf("screen modes:");
  49.     for(i=0;i<128;i++) if(M[i]) printf(" %2x",i); putchar('\n');}
  50. else if(!strcmp(s,"text")) {int i,j,k,l,m,n,om,nm=0,p;
  51.     struct {uns short cols,rows; byte n,mono;} mode[128],*M=mode; byte*q;
  52.     om=gp_mode();
  53.     for(i=0;i<128;i=i==8?0xd:i+1) if(gp_mode(i),gp_mode()==i) {M->n=i;
  54.         M->cols=ScreenCols(); M->rows=ScreenRows();
  55.         outportb(0x3c0,0x10); j=inportb(0x3c1);
  56.         if(j&1) continue; /* graphics */ M->mono=(j&2)>>1; M++;}
  57.     gp_mode(om); nm=M-mode;
  58.     printf("mode cols rows\nhex    text\n");
  59.     for(i=0;i<nm;i++) {M=mode+i;
  60.         printf("  %02x %3d %3d %4s\n",
  61.         M->n,M->cols,M->rows,
  62.         M->mono?"monochrome":"colour");}}
  63. else if(sscanf(s,"%x",&i)) setscreenmode(i);
  64. else {printf("I can't understand `%s'.\n",s);
  65.     printf("findmode all    print numbers of all screen modes\n");
  66.     printf("findmode text   print details of all screen text modes\n");
  67.     printf(\
  68. "findmode nn     set screen to mode nn, if nn is hex number (no `0x')\n");
  69.   printf("findmode        with no arg, print what mode the screen is in now");}}
  70.